<template>
  <el-form label-width="100px">
    <el-form-item label="API名称">
      <el-input v-model="dist_uri" placeholder="请输入API名称"></el-input>
    </el-form-item>
    <el-form-item label="配置文件路径">
      <el-input v-model="cinfig_uri"></el-input>
    </el-form-item>
    <el-form-item label-width="100px">
      <el-button type="primary" @click="submitForm" :loading="loading">保存并下载</el-button>
      <a ref="download" download="API备份文件" v-show="false"></a>
    </el-form-item>
  </el-form>

</template>

<script>
import { responseFormat } from '../common/dataFormat';
export default {
    data() {
      return {
        download_addr: '',
        dist_uri: '',
        cinfig_uri: '/etc/production.ini',
        loading: false
      };
    },
    methods: {
      submitForm() {
        this.loading = true;
        this.$http.get('/management/bak_api', {
          params: {
            cinfig_uri: this.cinfig_uri,
            dist_uri: this.dist_uri
          }
        }).then(res => {
            this.$message({
              message: '保存成功',
              type: 'success'
            });
            this.loading = false;
            this.$refs.download.href = res.data.download_addr;
            this.$refs.download.click();
        }, err => {
          this.loading = false;
          this.$message({
              message: err,
              type: 'error'
            })
        }).catch(err => {
          this.loading = false;
          this.$message({
              message: err,
              type: 'error'
            })
        })
      }
    }
  }
</script>
